<template>
    <div></div>
</template>

<script>
import verifyCode from "../../components/VerificationCode";
import { mapGetters } from "vuex";

export default {
    name: "RegisterVip",
    components: { verifyCode },
    data() {
        return {
            registerForm: {
                real_name: "",
                phone: "",
                code: "",
                bank_name: "",
                bank_code: "",
                bank_addr: "",
                idcard: "",
                pwd2: "",
                rf: "", // 推荐人编号
                node: "", //接点人编号
                seat: "",
                addrs: ""
            },
            recommendMan: "", //推荐人
            contaceMan: "", //接点人
            isPwd2: true,
            popupInfo: { type: 0, list: [] },
            moneyList: [3000, 5000, 10000, 20000],
            seatList: ["左", "中", "右"],
            show: false
        };
    },
    computed: {
        ...mapGetters(["userInfo"])
    },
    methods: {
        codeValue(value) {
            this.registerForm.code = value;
        },
        //检测推荐人
        checkInvestRecommend() {
            if (this.recommendMan == "") return this.fail("推荐人不能为空");
            this.load();
            this.$store
                .dispatch(types.INVEST_CHECKUSER, {
                    name: this.recommendMan,
                    check_invest: true
                })
                .then(res => {
                    this.clear();
                    console.log(res);
                    if (res.code == 0) {
                        this.recommendMan =
                            this.recommendMan + "(" + res.name + ")";
                        this.registerForm.rf = res.uid;
                        return;
                    }
                    this.recommendMan = "";
                    this.fail(res.msg);
                });
        },
        //检测接点人
        checkContactMan() {
            if (this.contaceMan == "") return this.fail("接点人不能为空");
            this.load();
            this.$store
                .dispatch(types.INVEST_CHECKUSER, {
                    name: this.contaceMan,
                    check_point: true
                })
                .then(res => {
                    this.clear();
                    console.log(res);
                    if (res.code == 0) {
                        this.contaceMan =
                            this.contaceMan + "(" + res.name + ")";
                        this.registerForm.node = res.uid;
                        return;
                    }
                    this.contaceMan = "";
                    this.fail(res.msg);
                });
        },
        //打开popup
        openPopup(index) {
            console.log(index);
            if (index == 0) {
                this.popupInfo.list = this.seatList;
                this.popupInfo.type = 0;
            }
            if (index == 1) {
                this.filterInvest();
                this.popupInfo.type = 1;
            }
            this.show = true;
        },
        //popup回掉
        popupChoice(value, type) {
            this.show = false;
            if (type == 0) return (this.registerForm.seat = value);
            if (type == 1) return (this.registerForm.amount = value);
        },
        //过滤投资金额
        filterInvest() {
            this.popupInfo.list = [];
            this.moneyList.filter(item => {
                if (item > this.computePrice(this.userInfo.invest))
                    this.popupInfo.list.push(item);
            });
        },
        //注册投资会员
        register() {
            console.log(this.registerForm);
            if (this.registerForm.real_name == "")
                return this.fail("真实姓名不能为空");
            if (this.registerForm.phone == "")
                return this.fail("手机号不能为空");
            if (this.validatePhone(this.registerForm.phone))
                return this.fail("请输入正确的手机号码");
            if (this.registerForm.code == "") return this.fail("请输入验证码");
            if (this.registerForm.bank_name == "")
                return this.fail("开户银行不能为空");
            if (this.registerForm.bank_code == "")
                return this.fail("银行卡号不能为空");
            if (this.registerForm.bank_addr == "")
                return this.fail("开户行地址不能为空");
            if (this.registerForm.idcard == "")
                return this.fail("身份证不能为空");
            if (this.registerForm.rf == "") return this.fail("推荐人不能为空");
            if (this.registerForm.node == "")
                return this.fail("接点人不能为空");
            if (this.registerForm.seat == "")
                return this.fail("请选择接点位置");
            if (this.registerForm.amount == "")
                return this.fail("请选择投资额度");
            if (this.isPwd2 && this.registerForm.pwd2 == "")
                return this.fail("二级密码不能为空");
            if (this.registerForm.seat == "左") this.registerForm.seat = 1;
            if (this.registerForm.seat == "中") this.registerForm.seat = 2;
            if (this.registerForm.seat == "右") this.registerForm.seat = 3;
            this.$store
                .dispatch(types.INVEST_REGISTER, this.registerForm)
                .then(res => {
                    console.log(res);
                    if (res.code !== 0) {
                        this.registerForm.seat = "";
                        this.registerForm.pwd2 = "";
                        this.registerForm.amount = "";
                        return this.fail(res.msg, 2000);
                    }
                    this.success("注册投资会员成功");
                    return;
                    this.$store
                        .dispatch(types.CART_PRE, {
                            giftID: this.goodsDetail.id
                        })
                        .then(res => {
                            console.log(res);
                            if (res.code !== 0) return;
                            this.$store.commit(types.SET_CART_SUBMIT, res);
                            this.$router.replace({ name: "shopping-submit" });
                        });
                });
        }
    }
};
</script>

<style scoped lang="scss">
</style>
